﻿/*
 * @Autor: PK
 */

using System.Collections.Generic;
using System.Xml;

namespace ShkSimulation.core.util.osm {
	
	public class Way : BaseItem {
	    public long ID {get; private set; }
        public bool Visible { get; private set; }
        public List<long> NodeIDs { get; private set; }
        //边界可以在场景中画出，方便判断
        public bool IsBoundary { get; private set; }
        public bool IsBuilding { get; private set; }
        public bool IsRoad { get; private set; }
        public float Height { get; private set; }
        
        public Way(XmlNode node) {
            NodeIDs = new List<long>();
            ID = GetAttribute<long>("id", node.Attributes);
            Visible = GetAttribute<bool>("visible", node.Attributes);
            //保存way中的nodes的id
            XmlNodeList nds = node.SelectNodes("nd");
            foreach (XmlNode n in nds) {
                long refNo = GetAttribute<long>("ref", n.Attributes);
                NodeIDs.Add(refNo);
            }
		    //判断是否是边界
            if (NodeIDs.Count > 1) {
                IsBoundary = NodeIDs[0] == NodeIDs[NodeIDs.Count - 1];
            }
       	    Height = 10.0f; 
            XmlNodeList tags = node.SelectNodes("tag");
            foreach (XmlNode t in tags) {
                string key = GetAttribute<string>("k", t.Attributes);
                if (key == "height") {
                    //不确定是建筑还是道路高度
                    Height = 0.3048f * GetAttribute<float>("v", t.Attributes);
                } else if (key == "building:levels") {
                    //建筑层数，每一层是3m
                     Height = 3.0f * GetAttribute<float>("v", t.Attributes);
                }else if (key == "building") {
                    //是建筑
                    IsBuilding = GetAttribute<string>("v", t.Attributes) == "yes";
                    Height = 10.0f;
                } else if (key == "highway") {
                    //是公路
                    IsRoad = true;
                }
            }
        }   
	}
}